r<template>
    <div>
        <el-form :rules="rules" ref="loginFrom" :model="loginForm" class="loginContainer">
            <h3 class="loginTitle">系统登录</h3>
            <el-form-item prop="username">
                <!--auto-complete  自动补全-->
                <el-input type="text" auto-complete="false" v-model="loginForm.id" placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input type="password" auto-complete="false" v-model="loginForm.password" placeholder="输入密码"></el-input>
            </el-form-item>

            <el-checkbox v-model="checked" class="loginRemember">记住我</el-checkbox>
            <el-button type="primary" style="width: 100%" @click="submitLogin">登录</el-button>

        </el-form>
    </div>
</template>

<script>
    import {postRequest} from "../utils/api";
    import axios from 'axios'
    import requset from "../utils/request"

    export default {
        name: "Login",
        data() {
            return {

                loginForm: {
                    id: '',
                    password: ''
                },
                checked: true,
                rules: {
                    id: [{required: true,message: '请输入用户名',trigger: 'blur'}],
                    password: [{required: true,message: '请输入密码',trigger: 'blur'}],

                }
            }
        },
        methods: {
            submitLogin(){
                this.$refs.loginFrom.validate((valid) => {
                    if(valid){
                        postRequest('/Login/login',this.loginForm).then(resp=>{

                            if (resp) {
                                //存储用户token
                                const tokenStr ="" +resp.obj.token;
                                window.sessionStorage.setItem('tokenStr',tokenStr)
                                window.sessionStorage.setItem('token', tokenStr);
                                this.$store.commit('initRoutes',resp.obj.user.user_id)
                                this.$store.commit('setToken',tokenStr)
                                localStorage.setItem("token",tokenStr)
                                this.$router.push('/main');

                            }
                        })

                    }else{
                        this.$message.error("请");
                        return false;
                    }

                });
            }
        }
    }
</script>

<style >
    .loginContainer {
        border-radius: 15px;
        background-clip: padding-box;
        margin: 180px auto;
        width: 350px;
        padding: 15px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6 ;
    }
    .loginTitle {
        margin: 0px auto 40px auto;
        text-align: center ;
    }
    .loginRemember {
        text-align: left;
        margin: 0px 0px 15px 0px  ;
    }
    .el-form-item__content {
        display: flex;
        align-items: center;
    }

</style>
